#!/bin/bash

set -e

VERSION=latest
if [ $# == 1 ] ; then
VERSION=$1
fi

cd ../scripts
python build_web_docker.py
wait
if [ $? -ne 0 ]; then
    exit $?
fi

cd ../docker

cp ../bin/web/docker/*.jar ./

IMAGE_NAME="tzfun/etcd-workbench:$VERSION"

echo Building dockerfile $IMAGE_NAME
docker buildx build --platform linux/amd64,linux/arm64,linux/arm64/v8,windows/amd64 -f Dockerfile -t $IMAGE_NAME --push .
wait
if [ $? -ne 0 ]; then
    exit $?
fi

# echo Pushing image $IMAGE_NAME
# docker push $IMAGE_NAME
# wait
# if [ $? -ne 0 ]; then
#     exit $?
# fi

rm *.jar